<?php
/**
 * Created by 784855684@qq.com.
 * Link: https://github.com/lichtung/wshore
 * User: linzh
 * Date: 6/30/17
 * Time: 2:50 PM
 */
declare(strict_types=1);


namespace application\module\admin\controller;


use application\module\admin\addon\Sign;
use wshore\core\Cookie;
use wshore\core\Response;
use wshore\core\Session;
use wshore\helper\Base64x;

class index extends admin
{

    public function index()
    {
        $this->doLayoutAssign();
        $this->display();
    }

    public function index2()
    {
        echo "this is index2";
    }

    /**
     * 授权访问文件浏览器
     * URL:admin/index/authexplorer
     * @param string $dir4explore
     */
    public function authExplorer($dir4explore = '')
    {
        Session::set('_auth_explorer_', WS_NOW);
        Response::redirect(WS_PUBLIC_URL . '/explorer.php?explorer' . (
            $dir4explore ? '&dir4explore=' . $dir4explore : ''
            ));
    }

    public function testcookie()
    {
        if ($cookie = Cookie::get('_sign_key_')) {
            $sign = Sign::getInstance();
            $signinfo = unserialize(Base64x::decode($cookie, $sign->encodeKey));
            if ($signinfo) {
                Session::set('_sign_key_', $signinfo);
            }
            $info = [
                'id' => $signinfo['id'],
                'last_time' => $signinfo['last_time'],
            ];
            $verify_key = sha1(md5(serialize($info) . $sign->encodeKey));
            if ($verify_key !== $signinfo['verify_key']) {
                # 无法通过验证
            }
        }
        dumpout($verify_key??null, $signinfo??null, Cookie::get('_sign_key_'), Session::get('_sign_key_'));
    }

    /**
     * 显示401页面
     * URL:/admin/index/showunauthorized
     */
    public function showUnauthorized()
    {
        $this->doLayoutAssign();
        $this->display('401');
    }

    /**
     * 显示404页面
     * URL:/admin/index/shownotfound
     */
    public function showNotFound()
    {
        $this->doLayoutAssign();
        $this->display('404');
    }

    /**
     * 显示500错误
     * URL:/admin/index/showinternalservererror
     */
    public function showInternalServerError()
    {
        $this->doLayoutAssign();
        $this->display('500');
    }
}